package cn.edu.java.io.inputstream;

import java.io.*;

public class SequenceInputStreamDemo {
    public static void main(String[] args) {
        try {
            // 创建两个输入流
            ByteArrayInputStream inputStream1 = new ByteArrayInputStream("Hello, ".getBytes());
            ByteArrayInputStream inputStream2 = new ByteArrayInputStream("World!".getBytes());

            // 创建SequenceInputStream，将两个输入流串联起来
            SequenceInputStream sequenceInputStream = new SequenceInputStream(inputStream1, inputStream2);


            // 从SequenceInputStream中读取数据并写入输出流
            int data;
            while ((data = sequenceInputStream.read()) != -1) {
                System.out.print((char) data);
            }

            // 关闭流
            sequenceInputStream.close();

            System.out.println("\n合并完成!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

